Ext.MessageBox.YES.text = '是';
Ext.MessageBox.NO.text = '否';
Ext.MessageBox.OK.text = '确定';
Ext.MessageBox.CANCEL.text = '取消';
Ext.MessageBox.OKCANCEL[0].text="取消";
Ext.MessageBox.OKCANCEL[1].text="确定";
Ext.MessageBox.YESNO[0].text="否";
Ext.MessageBox.YESNO[1].text="是";
Ext.MessageBox.YESNOCANCEL[0].text="取消";
Ext.MessageBox.YESNOCANCEL[1].text="否";
Ext.MessageBox.YESNOCANCEL[2].text="是";
Ext.Ajax.setTimeout(120000);
var storage = window.localStorage;

Ext.application({
    launch: function () {
        var formBase = {
            url: server+'/mobile/login.do',
            standardSubmit: false,
            items: [
                {
                    xtype: 'fieldset',
                    title: '晨熹',
                    instructions: 'Please enter the information above.',
                    defaults: {
                        labelAlign: 'left',
                        labelWidth: '40%'
                    },
                    items: [
                        {
                            xtype: 'textfield',
                            name: 'username',
                            required: true,
                            label: '帐号',
                            useClearIcon: false,
                            autoCapitalize: false
                        },
                        {
                            xtype: 'passwordfield',
                            name: 'password',
                            required: true,
                            label: '密码',
                            useClearIcon: false
                        },
                        {
                            xtype: 'checkboxfield',
                            name: 'remember',
                            label: '记住',
                            checked: false,
                            value: true,
                            listeners: {
                                uncheck: function (f) {
                                    storage.removeItem('username')
                                    storage.removeItem('password')
                                    storage.removeItem('remember')
                                }
                            }
                        }
                    ]
                },
                {
                    xtype: 'toolbar',
                    title: '协同管理专家',
                    docked: 'top'
                },
                {
                    xtype: 'toolbar',
                    docked: 'bottom',
                    items: [

                        {xtype: 'spacer'},
                        {
                            text: '重置',
                            handler: function () {
                                loginpage.reset();
                            }
                        },
                        {
                            text: '登录',
                            ui: 'confirm',
                            badgeText: '',
                            width: 100,
                            handler: function () {
                                formdata = loginpage.getValues(false);
                                if (formdata.remember) {
                                    storage.setItem('username', formdata.username);
                                    storage.setItem('password', formdata.password);
                                    storage.setItem('remember', formdata.remember);

                                }

                                loginpage.submit({
                                    waitMsg: {message: '请稍候...', cls: 'demos-loading'},
                                    success: function (form, result) {
                                        loginpage.hide();
                                        mainpage = new Ext.TabPanel({
                                            fullscreen: true,
                                            tabBarPosition: 'bottom',
                                            listeners: {
                                                'activeitemchange': function (con, newcard, oldcard) {
                                                    if (newcard.id == 'exitbtn') {
                                                        Ext.Msg.confirm("", "您确定要退出吗？", function (btn) {
                                                            if (btn == 'yes') {
                                                                Ext.Ajax.request({
                                                                    url: server+"/mobile/logout.do",
                                                                    success: function (res) {
                                                                        container.remove(mainpage);
                                                                        loginpage.show();
                                                                    }
                                                                });
                                                            } else {
                                                                return;
                                                            }
                                                        })
                                                    }
                                                }
                                            },
                                            items: [
                                                {
                                                    xtype: 'wfprocesslist',
                                                    iconCls: 'time',
                                                    title: '流程'
                                                },
                                                {   xtype: 'documentlist',
                                                    iconCls: 'bookmarks',
                                                    title: '文档',
                                                    html: ''
                                                },
                                                {
                                                    xtype: 'searchlist',
                                                    iconCls: 'search',
                                                    title: '搜索',
                                                    html: ''
                                                },
										        {xtype: 'main',iconCls: 'favorites',title: '工作台', html: ''},
                                                {
                                                    id: 'exitbtn',
                                                    iconCls: 'user',
                                                    title: '退出',
                                                    html: ''
                                                }
                                            ]

                                        });

                                        container.add(mainpage);

                                    },
                                    failure: function (form, result) {
                                        if(result.msg)
                                        Ext.Msg.alert(result.msg)
                                        else
                                        Ext.Msg.alert("网络异常")
                                    }
                                });
                            }
                        }
                    ]
                }
            ]
        };
        loginpage = new Ext.form.Panel(formBase);
        loginpage.setValues({username: storage.getItem('username'), password: storage.getItem('password'), remember: storage.getItem('remember')})
        var container = new Ext.Container({
            fullscreen: true,
            layout: 'fit',
            items: [loginpage]
        })

        if (Ext.os.deviceType == 'Phone') {
            win = Ext.Viewport.add(container);
            win.show();
        }
    }
});
